home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / util / moni / Scout-src.lha / source / objects / scout_inputhandlers.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-02-13  |  8.0 KB  |  246 lines

  1. /**
  2.  * Scout - The Amiga System Monitor
  3.  *
  4.  *------------------------------------------------------------------
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  * You must not use this source code to gain profit of any kind!
  21.  *
  22.  *------------------------------------------------------------------
  23.  *
  24.  * @author Andreas Gelhausen
  25.  * @author Richard Körber <rkoerber@gmx.de>
  26.  */
  27.  
  28.  
  29.  
  30. #include "system_headers.h"
  31.  
  32. static APTR InputPool = NULL;
  33.  
  34. __asm __saveds LONG inputlist_dspfunc(register __a2 char **array, register __a1 struct InputEntry *inputentry, register __a0 struct Hook *hook)
  35. {
  36.    if (inputentry) {
  37.       *array++ = inputentry->input_address;
  38.       *array++ = inputentry->input_name;
  39.       *array++ = inputentry->input_type;
  40.       *array++ = inputentry->input_pri;
  41.       *array++ = inputentry->input_data;
  42.       *array++ = inputentry->input_code;
  43.       *array   = NULL;
  44.    } else {
  45.       *array++ = ESC "bAddress";
  46.       *array++ = ESC "bln_Name";
  47.       *array++ = ESC "bln_Type";
  48.       *array++ = ESC "bln_Pri";
  49.       *array++ = ESC "bis_Data";
  50.       *array++ = ESC "bis_Code";
  51.       *array   = NULL;
  52.    }
  53.    return(0);
  54. }
  55.  
  56. struct Hook inputlist_dsphook = {
  57.  {NULL, NULL},
  58.  (ULONG (* )())inputlist_dspfunc,
  59.  NULL, NULL
  60. };
  61.  
  62. void FreeInputHandler (void)
  63. {
  64.     MyFreePoolStructs (&InputPool, inputtext, NULL, inputlist);
  65. }
  66.  
  67. int GetInputHandler (struct InputEntry **first) {
  68.    struct   Interrupt      *intr;
  69.    struct   Device         *input;
  70.    struct   InputEntry     *inputentry,*previous = NULL;
  71.    char     *tmp;
  72.    char     code[FILENAMELENGTH + 1];
  73.  
  74.    int inputcnt = 0;
  75.    *first = 0;
  76.  
  77.    if (!InputPool) InputPool = tbCreatePool(MEMF_CLEAR, 4096, 4096);
  78.  
  79.    if (clientstate) {
  80.       if (SendDaemon ("GetInputList")) {
  81.          while ((inputentry = tbAllocPooled(InputPool, sizeof(struct InputEntry))) \
  82.            && (ReceiveDecodedEntry ((UBYTE *) inputentry, sizeof (struct InputEntry)))) {
  83.             IsHex (inputentry->input_address, (long *) &inputentry->input_adr);
  84.  
  85.             if (! *first)
  86.                *first = inputentry;
  87.             if (previous)
  88.                previous->input_next = inputentry;
  89.  
  90.             inputcnt++;
  91.             previous = inputentry;
  92.          }
  93.       }
  94.    } else {
  95.       if (input = (struct Device *) FindName (&SysBase->DeviceList, "input.device")) {
  96.          tmp = (APTR) input;
  97.          tmp += 148;    /* Mir unbekannter Offsetname! */
  98.          if (intr = (struct Interrupt *) ((struct Interrupt *) tmp)->is_Node.ln_Succ) {
  99.             if (intr = (struct Interrupt *) intr->is_Node.ln_Succ) {
  100.                while ((intr->is_Node.ln_Succ != 0) && (inputentry = tbAllocPooled(InputPool, sizeof(struct InputEntry)))) {
  101.                   if (! *first)
  102.                      *first = inputentry;
  103.                   if (previous)
  104.                      previous->input_next = inputentry;
  105.  
  106.                   inputentry->input_adr = intr;
  107.  
  108.                   code[0] = '\0';
  109.                   if (points2ram((APTR) intr->is_Code)) {
  110.                      _sprintf (code, HELL "$%08lx" DUNKEL, intr->is_Code);
  111.                   } else {
  112.                      _sprintf (code, "$%08lx", intr->is_Code);
  113.                   }
  114.                   _sprintf (inputentry->input_address, "$%08lx", intr);
  115.                   strncpy (inputentry->input_name, nonetest (intr->is_Node.ln_Name), 27);
  116.                   strcpy (inputentry->input_type, GetNodeType (intr->is_Node.ln_Type));
  117.                   _sprintf (inputentry->input_pri, "%4ld ", intr->is_Node.ln_Pri);
  118.                   _sprintf (inputentry->input_data, "$%08lx", intr->is_Data);
  119.                   strcpy (inputentry->input_code, code);
  120.                   inputcnt++;
  121.  
  122.                   previous = inputentry;
  123.                   intr = (struct Interrupt *) intr->is_Node.ln_Succ;
  124.                }
  125.             }
  126.          }
  127.       }
  128.    }
  129.    return (inputcnt);
  130. }
  131.  
  132. void PrintInputHandlers (char *filename) {
  133.    int   i=1;
  134.    BPTR  handle;
  135.    struct InputEntry *entryp = NULL;
  136.  
  137.    handle = HandlePrintStart (filename);
  138.    if ((handle) && (PrintOneLine (handle, "\n  Address  Type       Pri    Data       Code     Name\n\n"))) {
  139.       if (! WI_InputHandler) {
  140.          i = GetInputHandler (&entryp);
  141.       }
  142.       if (i) {
  143.          for (i=0;;i++) {
  144.             if (WI_InputHandler)
  145.                DoMethod (inputlist,MUIM_List_GetEntry,i,&entryp);
  146.             if (!entryp) break;
  147.  
  148.             if (points2ram ((APTR) (entryp->input_adr->is_Code)))
  149.                strcpy (tmpstr, entryp->input_code+2);
  150.             else
  151.                strcpy (tmpstr, entryp->input_code);
  152.  
  153.             _sprintf (tmpstr2, " %s %-9s %4s %s %-9.9s %s\n", entryp->input_address, entryp->input_type, entryp->input_pri, entryp->input_data, tmpstr, entryp->input_name);
  154.             if (! (PrintOneLine (handle, tmpstr2)))
  155.                break;
  156.  
  157.             if (! WI_InputHandler)
  158.                entryp = entryp->input_next;
  159.          }
  160.       }
  161.    }
  162.    HandlePrintStop();
  163. }
  164.  
  165. void ShowInputHandler (void) {
  166.    struct InputEntry *input;
  167.  
  168.    ApplicationSleep();
  169.    set (inputlist,MUIA_List_Quiet,TRUE);
  170.    set (BT_InputRemove, MUIA_Disabled, TRUE);
  171.    set (BT_InputPriority, MUIA_Disabled, TRUE);
  172.  
  173.    FreeInputHandler();
  174.    inputcnt = GetInputHandler (&input);
  175.  
  176.    while (input) {
  177.       InsertBottomEntry (inputlist, (APTR *) &input);
  178.       input = input->input_next;
  179.    }
  180.  
  181.    SetCountText (inputcount, inputcnt);
  182.    AwakeApplication();
  183.    set (inputlist,MUIA_List_Quiet,FALSE);
  184. }
  185.  
  186. void SendInputList (void) {
  187.    struct InputEntry *input;
  188.  
  189.    FreeInputHandler();
  190.    inputcnt = GetInputHandler (&input);
  191.  
  192.    while (input) {
  193.       SendEncodedEntry ((UBYTE *) input, sizeof (struct InputEntry));
  194.       input = input->input_next;
  195.    }
  196.    FreeInputHandler();
  197. }
  198.  
  199.  
  200. char inputhandler_title[WINDOWTITLELEN];
  201.  
  202. void InputHandlerWindow (BOOL state) {
  203.    if (state) {
  204.       if (WI_InputHandler) {
  205.          ShowInputHandler();
  206.       } else {
  207.          WI_InputHandler = WindowObject,
  208.          MUIA_Window_Title, MyGetWindowTitle (inputhandler_title, "INPUTHANDLERS"),
  209.          MUIA_HelpNode, InputHandlersText,
  210.          MUIA_Window_ID, MakeListID('I','N','P','U'),
  211.          WindowContents, VGroup,
  212.             Child, inputlist = MyListviewObject ("COL=0 DELTA=8,COL=1 DELTA=8,COL=2 DELTA=8,COL=3 DELTA=8 P=\33r,COL=4 DELTA=8,COL=5",&inputlist_dsphook),
  213.             Child, MyBelowListview (&inputtext, &inputcount),
  214.             Child, MyVSpace(2),
  215.             Child, HGroup, MUIA_Group_SameSize, TRUE,
  216.                Child, BT_InputUpdate    = KeyButtonA (UpdateText  ,ID_INPUTUPDATE),
  217.                Child, BT_InputPrint     = KeyButtonA (PrintText   ,ID_INPUTPRINT),
  218.                Child, BT_InputRemove    = KeyButtonA (RemoveText  ,ID_INPUTREMOVE),
  219.                Child, BT_InputPriority  = KeyButtonA (PriorityText,ID_INPUTPRIORITY),
  220.                Child, BT_InputExit      = KeyButtonA (ExitText    ,ID_INPUTEXIT),
  221.             End,
  222.          End, End;
  223.  
  224.          DoMethod (AP_Scout,OM_ADDMEMBER,WI_InputHandler);
  225.          DoMethod (WI_InputHandler,MUIM_Window_SetCycleChain,inputlist,BT_InputUpdate,BT_InputPrint,BT_InputRemove,BT_InputPriority,BT_InputExit,NULL);
  226.  
  227.          SetCloseRequest (WI_InputHandler,ID_INPUTEXIT);
  228.          SetListActive (inputlist,ID_INPUTLV_ACTIVE);
  229.  
  230.          ShowInputHandler();
  231.  
  232.          SetWindowOpen (WI_InputHandler,inputlist,ID_INPUTEXIT);
  233.       }
  234.    } else if ((! state) && (WI_InputHandler)) {
  235.       SetWindowClose (WI_InputHandler,TRUE);
  236.  
  237.       FreeInputHandler();
  238.  
  239.       DoMethod (AP_Scout,OM_REMMEMBER,WI_InputHandler);
  240.       MUI_DisposeObject (WI_InputHandler);
  241.       WI_InputHandler = NULL;
  242.       inputlist = NULL;
  243.    }
  244. }
  245.  
  246.